package com.example.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

public class ImageViewActivity extends AppCompatActivity {
  boolean isImg1;
  ImageView imageView;
  @Override protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.image_view_layout);
    Toolbar toolbar=findViewById(R.id.toolbar);
    //toolbar.setTitle("图片浏览");
    setSupportActionBar(toolbar);
    imageView=(ImageView) findViewById(R.id.ImgView);
    imageView.setImageResource(R.mipmap.img1);
    isImg1=true;
    SetButtonsListener();


  }

  public void SetButtonsListener()
  {
    SetChangeImageListener();
    SetChangeAlphaListener();
  }
  private void DecreaseAlpha()
  {
    float alpha=imageView.getAlpha();
    if(alpha<=0)
      return;
    imageView.setAlpha(alpha-0.1f);
  }
  private void IncreaseAlpha()
  {
    float alpha=imageView.getAlpha();
    if(alpha>=1.0f)
      return;
    imageView.setAlpha(alpha+0.1f);

  }

  public void SetChangeAlphaListener()
  {
    Button switchButton=(Button) findViewById(R.id.Increase);
    switchButton.setOnClickListener(new View.OnClickListener() {
      @Override public void onClick(View v) {
        IncreaseAlpha();
      }
    });
    switchButton = (Button) findViewById(R.id.Decrease);
    switchButton.setOnClickListener(new View.OnClickListener() {
      @Override public void onClick(View v) {
        DecreaseAlpha();
      }
    });
  }
  public void SetChangeImageListener()
  {
    Button switchButton = (Button) findViewById(R.id.LastImageButton);

    switchButton.setOnClickListener(new View.OnClickListener() {
      @Override public void onClick(View v) {
        ChangeImage();
      }
    });
    switchButton = (Button) findViewById(R.id.NextImageButton);
    switchButton.setOnClickListener(new View.OnClickListener() {
      @Override public void onClick(View v) {
        ChangeImage();
      }
    });
  }
  public void ChangeImage()
  {
    if(isImg1)
    {
      imageView.setImageResource(R.mipmap.img2);
      isImg1=false;
    }
    else
    {
      imageView.setImageResource(R.mipmap.img1);
      isImg1=true;
    }

  }
  public void BackToLastActivity(View view)
  {
    Intent intent = new Intent(this, LoginActivity.class);
    startActivity(intent);
  }
  public void GoToNextActivity(View view)
  {
    Intent intent = new Intent(this, ListViewActivity.class);
    startActivity(intent);
  }
}
